<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/8/27
 * Time: 10:38
 */

namespace Biz\validate\activity;


class Meal extends \Doraemon\pockets\validate\Base
{
    public static function rules()
    {
        return [

            ['meal_title',  'required', null, '请填写套餐名称',  ['create', 'update']],

            ['start_time',  'required', null, '请选择开始时间',  ['create', 'update']],
            ['end_time',  'required', null, '请选择结束时间',  ['create', 'update']],

            ['cover_img', 'required', null, '请上传主图', ['create', 'update']],

            ['meal_img_info',  'required', null, '请上传说明图片',  ['create', 'update']],
            ['meal_img_info', 'callback', ['callback' => [new self(), 'checkMealImg']], '请上传说明图片', ['create','update']],
            ['meal_img_info', 'callback', ['callback' => [new self(), 'checkImagesContent']], '说明图片最多支持8张图', ['create','update']],

            ['meal_desc',  'required', null, '请填写说明文字', ['create', 'update']],
            ['meal_desc',  'length', '1,50', '套餐说明最大50个字符', ['create', 'update']],
        ];
    }

    public function checkMealImg($value)
    {
        if(empty($value)){
            return false;
        }

        return true;
    }

    public function checkImagesContent($value)
    {

        $value = json_decode($value,true);

        //商品图片最多支持8张图
        if(count($value)>8) return false;

        return true;
    }
}